<?php
/**
 * CreateUser: zlh
 * CreateTime: 2022/4/12 9:58
 * Remark:
 */

namespace App\Http\Controllers\Approval;

use App\Consts\ResponseConsts\ResponseStatusConsts;
use App\Func\ResponseFunc;
use App\Http\Controllers\Controller;
use App\Http\Requests\Approval\AddOldDingTalkApprovalTempPost;
use App\Http\Requests\Contract\ListContractTypeGet;
use App\Service\Approval\OldDingTalkApprovalTemplateService;

class OldDingTalkApprovalTemplateController extends Controller
{
    private OldDingTalkApprovalTemplateService $_oldDingTalkApprovalTempService;

    public function __construct()
    {
//        $this->middleware([
//           'approvalTemplateLeg'
//        ]);
        $this->_oldDingTalkApprovalTempService = new OldDingTalkApprovalTemplateService();
    }

    /**
     * @return \Illuminate\Http\JsonResponse
     */
    public function getOldDingTalkApprovalTempSelect($dingTalkApprovalTempSelectType): \Illuminate\Http\JsonResponse
    {
        return ResponseFunc::returnJson(
            'ok',
            $this->_oldDingTalkApprovalTempService->getOldDingTalkApprovalTempSelect($dingTalkApprovalTempSelectType),
            '获取审批模板下拉成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * @param AddOldDingTalkApprovalTempPost $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addOldDingTalkApprovalTemp(AddOldDingTalkApprovalTempPost $request): \Illuminate\Http\JsonResponse
    {
        $data = $request->all();
        $res =  $this->_oldDingTalkApprovalTempService->addOldDingTalkApprovalTemp($data);
        return ResponseFunc::returnJson(
            'ok',
            [
                "contract_type_id" => $res
            ],
            '新增审批模板成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * @param $dingTalkApprovalTempId
     * @return \Illuminate\Http\JsonResponse
     */
    public function delOldDingTalkApprovalTemp($dingTalkApprovalTempId): \Illuminate\Http\JsonResponse
    {
        $this->_oldDingTalkApprovalTempService->delOldDingTalkApprovalTemp($dingTalkApprovalTempId);
        return ResponseFunc::returnJson(
            'ok',
            null,
            '删除审批模板成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }

    /**
     * 获取
     * @param ListContractTypeGet $request
     * @return mixed
     */
    public function getOldDingTalkApprovalTempList(ListContractTypeGet $request): mixed
    {
        $pageSize = $request->get('page_size');
        $filters = $request->get('filters');
        return ResponseFunc::returnJson(
            'ok',
            $this->_oldDingTalkApprovalTempService->getOldDingTalkApprovalTempList($pageSize,$filters),
            '获取审批模板列表成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS
        );
    }

    /**
     * 获取钉钉审批模板详情
     * @param int $dingTalkApprovalTempId
     * @return \Illuminate\Http\JsonResponse
     */
    public function getOldDingTalkApprovalTempInfo(int $dingTalkApprovalTempId): \Illuminate\Http\JsonResponse
    {
        return ResponseFunc::returnJson(
            'ok',
            $this->_oldDingTalkApprovalTempService->getOldDingTalkApprovalTempInfo($dingTalkApprovalTempId),
            '获取审批模板详情成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS,
        );
    }



}